#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
using namespace std;

class Solution {
public:
    bool incl(unordered_map<char, int> hash, unordered_map<char, int> exp) {
        for (auto e : exp) {
            if (hash.find(e.first) == hash.end() || hash[e.first] < e.second) {
                return false;
            }
        }
        return true;
    }
    vector<int> findAnagrams(string s, string p) {
        unordered_map<char, int> hash, exp;
        for (auto e : p) ++exp[e];

        vector<int> res;
        deque<int> dq;
        for (int i = 0; i < s.size(); ++i) {
            dq.push_back(i);
            ++hash[s[i]];
            while (incl(hash, exp)) {
                if (hash == exp) {
                    res.push_back(dq.front());
                    break;
                }
                hash[s[dq.front()]]--;
                if (hash[s[dq.front()]] == 0) hash.erase(s[dq.front()]);

                dq.pop_front();
            }
        }

        return res;
    }
};

int main()
{
    vector<int> res = Solution().findAnagrams("baa", "aa");

    for (auto e : res) {
        cout << e << endl;
    }
    return 0;
}